package com.hualan.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hualan.domain.Article;
import com.hualan.domain.ArticleAndTeacher;
import com.hualan.mapper.ArticleMapper;
import com.hualan.service.impl.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ArticleServiceImpl implements ArticleService {

    @Autowired
    private ArticleMapper articleMapper;
    @Override
    public List<Article> findThreeArticle() {
        return articleMapper.findThreeArticle();
    }

    @Override
    public List<ArticleAndTeacher> findLikeArticle(String articleName) {
        return articleMapper.findLikeArticle(articleName);
    }

    @Override
    public int insertArticle(Article article) {
        return articleMapper.insertSelective(article);
    }

    @Override
    public List<Article> findAllArticle() {
        return articleMapper.findAllArticle();
    }

    @Override
    public int updateArticle(Article article) {
        return articleMapper.updateByPrimaryKeySelective(article);
    }

    @Override
    public int deleteArticle(Long id) {
        return articleMapper.deleteByPrimaryKey(id);
    }

    @Override
    public List<ArticleAndTeacher> findArticleAndTeacher() {

        //查询前,加分页配置
        PageHelper.startPage(0,3);
        //查询所有数据中,指定页的数据
        List<ArticleAndTeacher> list = articleMapper.findArticleAndTeacher();
        //查询后,搜集分页信息
        PageInfo<ArticleAndTeacher> pageInfo = new PageInfo<>(list);


        return articleMapper.findArticleAndTeacher();
    }
}
